package br.com.future.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import br.com.future.bo.ClienteBO;
import br.com.future.model.Cliente;

import com.opensymphony.xwork2.ActionSupport;

public class ClienteAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<Cliente> clientes;
	private String pesquisarNomeCliente = "";
	
	@Action(value="listarCliente",results={
			@Result(name="cadastrar",location="/relClienteProc.jsp")
	})
	public String listarClientes(){
		this.setClientes(ClienteBO.consultarCliente());
			return "cadastrar";
	}
	
	@Action(value = "filtrarClienteRel", results = { @Result(name = "success", location = "/relClienteProc.jsp") })
	public String filtrarClientes() {
		if (pesquisarNomeCliente != null) {
			this.clientes = ClienteBO.consultarCliente(pesquisarNomeCliente);
		} else {
			this.clientes = ClienteBO.consultarCliente();
		}
		return SUCCESS;
	}

	public List<Cliente> getClientes() {
		return clientes;
	}

	public void setClientes(List<Cliente> clientes) {
		this.clientes = clientes;
	}

	public String getPesquisarNomeCliente() {
		return pesquisarNomeCliente;
	}

	public void setPesquisarNomeCliente(String pesquisarNomeCliente) {
		this.pesquisarNomeCliente = pesquisarNomeCliente;
	}
	
}
